package org.thread.test02.demo04.demo1;

/**
 *  计算守护线程
 * @author ZJL
 * @date 2025-03-07
 */
public class GuardingThread extends Thread {
    private FileData fileData;

    public FileData getFileData() {
        return fileData;
    }

    public void setFileData(FileData fileData) {
        this.fileData = fileData;
    }

    @Override
    public void run() {
        while (true) {
            if (this.getFileData().getTotalSize()==0) {
                continue;
            }
            double percent = 0;
            percent = this.fileData.getCopiedSize() * 1.0 / this.fileData.getTotalSize() * 100; ;
            System.out.printf("完成进度：%.2f%%\n", percent);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

    }
}
